package com.exam.jingdong;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * date:
 * description:
 */
public class Solution002 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[][] edges = new int[m][3];
        int min = Integer.MAX_VALUE;
        int max = Integer.MIN_VALUE;
        List<List<int[]>> adjacent = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            adjacent.add(new ArrayList<>());
        }
        for (int i = 0; i < m; i++) {
            int x = scanner.nextInt();
            int y = scanner.nextInt();
            int weight = scanner.nextInt();
            adjacent.get(x - 1).add(new int[]{y - 1, weight});
            adjacent.get(y - 1).add(new int[]{x - 1, weight});
            min = Math.min(min, weight);
            max = Math.max(max, weight);
        }
        int load = min;
        for (int i = min; i <= max; i++) {
            boolean[] visited = new boolean[n];
            dfs(0, i, adjacent, visited);
            if(!validate(visited)){
                break;
            }else{
                load = i;
            }
        }
        System.out.println(load);
    }

    private static void dfs(int i, int weight, List<List<int[]>> adjacent, boolean[] visited) {
        visited[i] = true;
        ArrayList<Integer> next = new ArrayList<>();
        for (int j = 0; j < adjacent.get(i).size(); j++) {
            int[] edge = adjacent.get(i).get(j);
            if(visited[edge[0]]){
                continue;
            }
            if(weight <= edge[1]){
//                visited[j] = true;
                next.add(edge[0]);
            }
        }
        for (Integer index : next) {
            dfs(index, weight, adjacent, visited);
        }
    }

    private static boolean validate(boolean[] visited) {
        for (boolean marker : visited) {
            if(!marker){
                return false;
            }
        }
        return true;
    }
}
